package com.moxiao.yfjh.module.blind.dal.mysql.memberLike;

import com.moxiao.yfjh.module.blind.controller.admin.memberLike.vo.MemberLikeExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberLike.vo.MemberLikePageReqVO;
import com.moxiao.yfjh.module.blind.controller.app.controller.exchage.vo.AppMemberLikeReqVO;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberLike.MemberLikeDO;
import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberSayHello.MemberSayhelloDO;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.blind.controller.admin.memberLike.vo.*;

/**
 * 相亲会员喜欢我 Mapper
 *
 * @author mx
 */
@Mapper
public interface MemberLikeMapper extends BaseMapperX<MemberLikeDO> {

    default PageResult<MemberLikeDO> selectPage(MemberLikePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberLikeDO>()
                .eqIfPresent(MemberLikeDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberLikeDO::getIssue, reqVO.getIssue())
                .eqIfPresent(MemberLikeDO::getReceive, reqVO.getReceive())
                .eqIfPresent(MemberLikeDO::getLikeEachother, reqVO.getLikeEachother())
                .eqIfPresent(MemberLikeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberLikeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberLikeDO::getId));
    }

    default Long selectCount(MemberLikePageReqVO reqVO) {
        return selectCount(new LambdaQueryWrapperX<MemberLikeDO>()
                .eqIfPresent(MemberLikeDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberLikeDO::getIssue, reqVO.getIssue())
                .eqIfPresent(MemberLikeDO::getReceive, reqVO.getReceive())
                .eqIfPresent(MemberLikeDO::getLikeEachother, reqVO.getLikeEachother())
                .eqIfPresent(MemberLikeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberLikeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberLikeDO::getId));
    }

    default List<MemberLikeDO> selectList(MemberLikeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberLikeDO>()
                .eqIfPresent(MemberLikeDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberLikeDO::getIssue, reqVO.getIssue())
                .eqIfPresent(MemberLikeDO::getReceive, reqVO.getReceive())
                .eqIfPresent(MemberLikeDO::getLikeEachother, reqVO.getLikeEachother())
                .eqIfPresent(MemberLikeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberLikeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberLikeDO::getId));
    }

    default List<MemberLikeDO> selectLikeList(AppMemberLikeReqVO reqVO) {
        LambdaQueryWrapperX<MemberLikeDO> memberLikeDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MemberLikeDO>()
                .eqIfPresent(MemberLikeDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberLikeDO::getLikeEachother, reqVO.getLikeEachother())
                .eqIfPresent(MemberLikeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberLikeDO::getCreateTime, reqVO.getCreateTime());
        if(StringUtils.isNotEmpty(reqVO.getIssue())){
            memberLikeDOLambdaQueryWrapperX.and(wrapper->wrapper.eq(MemberLikeDO::getIssue, reqVO.getIssue()))
                    .or(wrapper->wrapper.eq(MemberLikeDO::getReceive, reqVO.getIssue()).eq(MemberLikeDO::getLikeEachother, (byte) 1));
        }
        if(StringUtils.isNotEmpty(reqVO.getReceive())){
            memberLikeDOLambdaQueryWrapperX.and(wrapper->wrapper.eq(MemberLikeDO::getReceive, reqVO.getReceive()))
                    .or(wrapper->wrapper.eq(MemberLikeDO::getIssue, reqVO.getReceive()).eq(MemberLikeDO::getLikeEachother, (byte) 1));
        }
        if (Objects.equals(reqVO.getHaveMember(),1)){
            memberLikeDOLambdaQueryWrapperX.orderByDesc(MemberLikeDO::getId);
        }else {
            memberLikeDOLambdaQueryWrapperX.orderByAsc(MemberLikeDO::getId);
        }
        return selectList(memberLikeDOLambdaQueryWrapperX);
    }
}
